package main

import (
	"context"
	"github.com/cloudwego/hertz/pkg/app/server"
	"github.com/cloudwego/hertz/pkg/common/hlog"
	_ "github.com/cloudwego/hertz/pkg/common/hlog"
	"github.com/cloudwego/hertz/pkg/common/tracer/stats"
	_ "github.com/cloudwego/hertz/pkg/common/tracer/stats"
	"os"
)

func Add[T string | int](a, b T) T {
	return a + b
}

func main() {
	Add(1, 3)
	add := Add("ab", "cd")
	print(add)
	f, err := os.OpenFile("./app.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
	if err != nil {
		panic(err)
	}
	defer func(f *os.File) {
		err := f.Close()
		if err != nil {
			hlog.CtxErrorf(context.Background(), "close file error: %s", err)
		}
	}(f)
	hlog.SetOutput(f)

	h := server.Default(server.WithTraceLevel(stats.LevelBase))
	SetupRoutes(h) //注册路由
	h.Spin()
}

type Result[T string | int | interface{}] struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data T      `json:"data"`
}
